<template lang="jade">
div
  m-title(icon='add',name='添加培训学校/机构')
  table.single
    // mf-row(name='培训学校/机构显示位置')
    //   select(v-model='p.show',placeholder='请选择显示位置')
    //     option(value='', selected) 请选择
    //     option(v-for='(n,i) in show', :value='i') {{n}}
    mf-row(name='培训学校/机构')
      select(v-model='p.category',placeholder='请选择培训学校/机构')
        option(value='', selected) 请选择
        option(v-for='(n,i) in category', :value='i') {{n}}
    mf-row(name='类别')
      select(v-model='p.type',placeholder='请选择类别')
        option(value='', selected) 请选择
        option(v-for='(n,i) in type', :value='i') {{n}}
    mf-row(name='是否收费')
      select(v-model='p.needfee',placeholder='请选择是否收费')
        option(v-for='(n,i) in needfee', :value='n.id') {{n.name}}
    mf-row(name='价格', v-if="p.needfee == 1")
      input(type = 'text',v-model='p.price',placeholder='请填写视频价格')
    mf-row(name='题库价格', v-if="p.needfee == 1")
      input(type = 'text',v-model='p.qprice',placeholder='请填写题库价格')
    mf-row(name='视频+题库价格', v-if="p.needfee == 1")
      input(type = 'text',v-model='p.aprice',placeholder='请填写题库价格')
    mf-row(name='名称')
      input(type = 'text',v-model='p.name',placeholder='请填写名称')
    mf-row(name='地址')
      input(type = 'text',v-model='p.address',placeholder='请填写地址', id="address")
      input(type = 'checkbox', v-model='online')
      label 在线课程（选择后设置为在线课程）
    mf-row(name='外层展示图片')
      mf-upload(uploadid='img', amount='1', project='xiongan', category='logo', :data='p.img', @upload_data='text',style='marginTop:20px')
      p(style='marginBottom:0px') 
    mf-row(name='题库展示图片')
      mf-upload(uploadid='quesimg', amount='1', project='xiongan', category='logo', :data='p.quesimg', @upload_data='text2',style='marginTop:20px')
      p(style='marginBottom:0px') 
    mf-row(name='简介')
      textarea#summary.editor(style='width: 500px; height: 200px;', v-model='p.summary') {{p.summary}}
    div(style="display:none")
      mf-row(name='优势')
        textarea#merit.editor(style='width: 500px; height: 200px;', v-model='p.merit') {{p.merit}}
    mf-row(name='优势图片添加', style="display:none")
      mf-upload(uploadid='img1', amount='10',project='xiongan', category='logo', :data='p.imgs',@upload_data='text1',style='marginTop:20px')
      p(style='marginBottom:0px') 优势图片尺寸 375px（宽）*210px（高），最多可上传10张优势图片
    mf-row(name='排序')
      input(type = 'text',v-model='p.sort',placeholder='请填写排序')
    mf-row
      button(@click='button') 添加
</template>

<script>
export default {
	data () {
		return {
      category:['学校','机构'],
      //type:['精品培训','职称考试','合作培训'],
      type:['精品培训'],
      needfee:[
        {
          id:0,
          name:"免费"
        },
        {
          id:1,
          name:"收费"
        },
      ],
      show:['两端显示','用户端','企业端'],
      p:{
        show:0,
        category:'',
        type:'',
        name:'',
        address:'',
        img:[],
        quesimg:[],
        summary:'',
        merit:'',
        sort:0,
        imgs:[],
        needfee:0,
        price:'',
        qprice:'',
        aprice:'',
      },
      online:false,
		}
	},
  watch:{
    online(val){
      if(val){
        this.p.address = "在线";
        $("#address").hide();
      }else{
        this.p.address = "";
        $("#address").show();
      }
    },
  },
	methods: {
    loadAfter(res){
		},
    text(data){
			this.p.img = data
		},
    text1(data){
			this.p.imgs = data
    },
    
    text2(data){
			this.p.quesimg = data
    },

    button(){
      summary.sync()
      merit.sync()
      this.p.summary = this.$dom.id('summary').value
      this.p.merit = this.$dom.id('merit').value
      if(this.p.show !=0 && this.p.show !=1 && this.p.show !=2){
        this.$msg.error('请选择显示位置!')
        return
      }
      if(this.p.name == ''){
        this.$msg.error('请填写课程名称!')
        return
      }
      if(this.p.img.length == 0 ){
        this.$msg.error('请上传图片!')
        return
      }
      if(this.p.type != 0 && this.p.type != 1 && this.p.type != 2){
        this.$msg.error('请选择类型!')
        return
      }
      if(this.p.category != 0 && this.p.category != 1){
        this.$msg.error('请选择培训学校/机构!')
        return
      }
      if(this.p.address == ''){
        this.$msg.error('请填写地址!')
        return
      }
      if( this.p.summary == ''){
        this.$msg.error('请填写简介!')
        return
      }
      // if(this.p.merit == ''){
      //   this.$msg.error('请填写优势!')
      //   return
      // }
      this.$ajax.post('cultivate/add/school',this.p,(res)=>{
        this.$msg.success(res.message)
        setTimeout("window.location.href='./school_list.html'",1500)
      },(res)=>{
        this.$msg.error(res.message)
      })
    },
    
	}
}
</script>